// pages/view-text/view-text.js
const WxParse= require('../../wxParse/wxParse.js');
import { getNewsDetail} from "../../utils/api.js";
import { tsFormatTime } from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    textData:{},
    nodes: [{
      name: 'div',
      attrs: {
        class: 'div_class',
        style: 'line-height: 60px; color: red;'
      },
      children: [{
        type: 'text',
        text: 'Hello&nbsp;World!'
      }]
    }],
    viewId: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  getData: function(Type){
    getNewsDetail(this.data.viewId, (data) => {
      var article = data.content;
      WxParse.wxParse('article', 'html', article, this, 5);
      data.edittime = tsFormatTime(data.edittime, "Y-M-D h:m");
      console.log(data)
      this.setData({
        textData: data
      });
      if(Type){
        // 隐藏导航栏加载框
        wx.hideNavigationBarLoading();
        // 停止下拉动作
        wx.stopPullDownRefresh();
      }
    });
  },
  onLoad: function (options) {
    this.setData({
      viewId: options.id
    })
    this.getData();
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    this.getData(true);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})